<script>
    jQuery("#current_user").val('<?php echo $user;?>');
    jQuery("a[title='Coupon templates graphics']").attr('action','coupon_template_graphic&user=<?php echo $user;?>');
    jQuery("a[title='Contract overview']").attr('action','coupon_contract_overview&user=<?php echo $user;?>');
    jQuery("a[title='Dashboard']").attr('action','app_setting&user=<?php echo $name;?>&app=coupon');
    jQuery("a[title='Facebook app credential']").attr('action','coupon_facebook_setting&user=<?php echo $name;?>&app=coupon');
  <?php if($app == 'coupon'){?>
     jQuery('#coupon').show();
     function set_size(){
        var size = jQuery("#result").height();
        size = size+50;
        jQuery(".pp_content").attr('style','height:'+size+'px');
    }
                    jQuery('#setting').hide();
                    jQuery('#systemLog').hide();
                    jQuery('#inner_content').css('width','87%');
                        jQuery('#inner_content').css('float','right');
                        jQuery('#side-nav').fadeIn('normal');
                      jQuery.each(jQuery("#coupon li"),function(){
                          jQuery(this).attr('class','');
                          if(jQuery(this).children().attr('title') == 'Dashboard'){
                              jQuery(this).attr('class','current');
                          }
                      });
                        <?php }?>
    </script>
    <style>
        th.column-CouponTemplateName{
            width:150px;
        }
    </style>
<div class="w100p bgl">
    <div class="w100p bgr">
        <div class="inner_container gallery1">
      
            <table class="widefat" cellspacing="0" style="width: 60%;">
                <thead>
                    
                    <tr style="">
                        <th style="border: none;width: 100px;">Statistics</th>                          
                        <th style="text-align: center;width: 60px; text-align: center; border-bottom: 0; border-top: 0;"></th> 
                    </tr>
                    <tr>
                                               
                    </tr>
                </thead>
                <tbody>
                    <tr class="bg_gray1">
                        <td style="font-weight: bold">Active campaign:</td>
                        <td style="border-right: 1px solid #fff" ><p><?php echo $active_campaign; ?></p></td>  
                      
                    </tr>                    
                    <tr class="bg_gray2">
                        <td style="font-weight: bold">Total number of campaigns:</td>
                        <td style="border-right: 1px solid #fff"><p><?php echo empty($number_of_campaign)?0:$number_of_campaign;  ?></p></td>
                       
                    </tr>
                    <tr class="bg_gray1">
                        <td style="font-weight: bold">New coupons last 24h:</td>
                        <td style="border-right: 1px solid #fff"><p><?php echo empty($number_of_coupon)? 0:$number_of_coupon;  ?></p></td>
                        
                    </tr>
                    <tr class="bg_gray1">
                        <td style="font-weight: bold">Total number of coupons:</td>
                        <td style="border-right: 1px solid #fff"><p><?php echo empty($total_number_of_coupon)? 0:$total_number_of_coupon;  ?></p></td>
                        
                    </tr>
                    <tr class="bg_gray1">
                        <td style="font-weight: bold">Sales amount last 24h:</td>
                        <td style="border-right: 1px solid #fff"><p><?php echo empty($total_sales)? 0:$total_sales  ?></p></td>
                        
                    </tr>
                     <tr class="bg_gray1">
                        <td style="font-weight: bold">Total sales amount:</td>
                        <td style="border-right: 1px solid #fff"><p><?php echo empty($sales)? 0:$sales  ?></p></td>
                        
                    </tr>
                   
                    
                </tbody>
            </table>
            <p></p>
            <table class="widefat" cellspacing="0">
                <thead>
                    <tr>
                        <?php print_column_headers('stFacebookToolbox_stFacebookToolbox'); ?>
                    </tr>
                </thead>

                <tbody>
                <?php
                if (count($results) > 0) {
                    
                    $tr_class = "";
                    $upload_data = wp_upload_dir();
                    foreach ($results as $result) {
                        $array = explode('-',substr($result->CouponGeneratedDateTime,0,11));
                        
                        $datetime = $array[2].'.'.$array[1].'.'.$array[0].' '.substr($result->CouponGeneratedDateTime,11);
                       // $description  = (strlen($result->CouponTemplateDescription) > 35)?substr($result->CouponTemplateDescription,0,35).'...':$result->CouponTemplateDescription;
                        if( empty($tr_class) || $tr_class == "class='bg_gray2'"){
                            $tr_class = "class='bg_gray1'";
                        }else{
                            $tr_class = "class='bg_gray2'";
                        }
                         $array = explode('-',substr($result->ValidFromDateTime,0,11));
                         $from = $array[2].'.'.$array[1].'.'.$array[0];
                         $array = explode('-',substr($result->ValidToDateTime,0,11));
                         $to = $array[2].'.'.$array[1].'.'.$array[0];
                         $sales = $model->get_sales($result->CouponTemplateID);
                         $coupon = $model->get_coupon($result->CouponTemplateID);
                         $amount = ($coupon == 0)?0:round($sales/$coupon*100,2);
                        echo "<tr id='$result->CouponTemplateID' $tr_class  >"
                        . "<td>" 
                        . $result->CouponTemplateName
                         . "<div class=\"row-actions short_action\">"
                        . "<span  short_action='' style='cursor:pointer;' id='' action='' class='edit'  onclick='jQuery.prettyPhoto.loadPage(\"coupon&template_id=$result->CouponTemplateID\",null,null,function(){set_size();});'>Show coupons</span>  | "
                         . "<span  short_action='' style='cursor:pointer;' id='' action='' class='edit'  onclick='jQuery.prettyPhoto.loadPage(\"customer&template_id=$result->CouponTemplateID\",null,null,function(){set_size();});'>Customers</span>"       
                         . "</div>"
                        . "</td>"
                        . "<td>"
                        . $from
                        . "</td>"
                        . "<td>"
                        . $to
                        . "</td>"
                        . "<td>"
                        . $coupon
                        . "</td>"
                        . "<td>"
                        . $model->get_customers($result->CouponTemplateID)
                        . "</td>"
                        . "<td>"
                        . $sales
                        . "</td>"
                         . "<td>"
                        . $amount.'%'
                        . "</td>"
                        . "</tr>"
                        ;
                    }
                }
                ?>
                </tbody>
            </table>
            <div class="page_d">
                <?php echo $pagination?>
                <div class="cl"></div>
            </div>
            
        </div>
    </div>
</div>
